local yicheng = fk.CreateSkill{
    name = "steam__yicheng",
}

yicheng:addEffect("active",{
    anim_type = "support",
    prompt = "#steam__yicheng_recast-ask",
    card_num = 0,
    target_num = 1,
    can_use = function(self, player)
      return player:getMark("steam__yicheng-turn")==0
    end,
    target_filter = function(self,player, to_select, selected)
      return #selected == 0 and to_select ~= player
    end,
    on_use = function(self, room, effect)
      local player = effect.from
      local target =effect.tos[1]
      local player_hands = player:getCardIds("he")
      local target_hands = target:getCardIds("he")
      local extra_data = {}
      local visible_data = {}
      for _, id in ipairs(player_hands) do
        if not player:cardVisible(id) then
          visible_data[tostring(id)] = false
        end
      end
      for _, id in ipairs(target_hands) do
        if not player:cardVisible(id) then
          visible_data[tostring(id)] = false
        end
      end
      if next(visible_data) == nil then visible_data = nil end
      extra_data.visible_data = visible_data
      local cards = room:askForPoxi(player, "steam__yicheng_recast", {
        { player.general, player_hands },
        { target.general, target_hands },
      }, extra_data, true)
      local peach = table.find(cards, function(id)
        return Fk:getCardById(id).name == "peach"
      end)
      local slash=table.filter(cards,function(cid) return Fk:getCardById(cid).trueName=="slash" end)
      local mycards=table.filter(cards,function(cid) return table.contains(player_hands,cid) end)
      local othercards=table.filter(cards,function(cid) return table.contains(target_hands,cid) end)
  
      if peach then
        room:throwCard(mycards, self.name, player, player)
        room:throwCard(othercards, self.name, target, player)
      else
        room:recastCard(mycards, player, self.name)
        room:recastCard(othercards, target, self.name)
      end
      if #slash > 0 then
        room:obtainCard(player, slash, true, fk.ReasonGive)
        room:setPlayerMark(player, "steam__yicheng-turn",1)
        
      end
    end,
  })
yicheng:addEffect(fk.EnterDying,{
    mute=true,
    can_trigger = function(self, event, target, player, data)
      return player:hasSkill(self) and player:getMark("steam__yicheng-turn")==0
    end,
    on_cost = function(self, event, target, player, data)
      local success, dat =  player.room:askForUseActiveSkill(player, "steam__yicheng", "枙城", true,nil,false)
      if success and dat then
        self.cost_data = {cards = dat.cards, tos = dat.targets}
        return true
      end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:notifySkillInvoked(player, "steam__yicheng", "support")
    end,
  })

return yicheng